package edu.mis.modules.categoryOfGoods;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

import edu.mis.model.CategoryOfGoods;

public class CategoryOfGoodsController extends Controller {
	private static CategoryOfGoodsService service = new CategoryOfGoodsService();
	
	public void index() {
		render("category.html");
	}
	
	public void list() {
		setAttr("data", service.findAllCategoryOfGoods());
		renderJson();
	}
	
	@Before(CategoryOfGoodsValidator.class)
	public void save() {
		CategoryOfGoods category = getModel(CategoryOfGoods.class, "");
		if (category.getId() == null) //添加
			setAttr("result", service.saveCategory(category));
		else //修改
			setAttr("result", service.updateCategory(category));
		renderJson();
	}
	
	public void delete() {
		Integer id = getParaToInt("id");
		setAttr("result", id != null && service.deleteCategoryById(id));
		renderJson();
	}
}
